package InvestmentPojo;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;



public class InvestmentAction extends Action {


	  public ActionForward execute(ActionMapping mapping, ActionForm inForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String html = "";
		LinkedHashMap linkedHashMap=null;
	    // Get a list of properties from application resources.
		String formId = request.getParameter("formId");
		String selectedValue = (String)request.getParameter("key");
	    System.out.println("FormId============="+formId);
	    if(formId != null && formId !=""){
		Properties applicationConfigProperties = new Properties(System.getProperties());
		String path = request.getSession().getServletContext().getRealPath("/");
		FileInputStream fis=new FileInputStream(path+"FemaProperties/ApplicationResources_Form_"+formId+".properties");
		applicationConfigProperties.load(fis);
	    //Starts.
	    if (selectedValue != null && !"".equals(selectedValue)) {
	    System.out.println("This is html response---"+selectedValue);	    
        HashMap map=new HashMap(applicationConfigProperties);
       
        Iterator mapIterator=map.entrySet().iterator();
        	 linkedHashMap=new LinkedHashMap();
        	while(mapIterator.hasNext()){
            Map.Entry pairs = (Map.Entry)mapIterator.next();
            String key=pairs.getKey().toString();
            String arr[] = key.toString().split("~");
            if(selectedValue.equals(arr[0])){
            	switch (Integer.parseInt(formId))
            	{    
       case 1:
                if("1".equals(arr[1].toString())){
                    linkedHashMap.put("1Eligiblity to invest", applicationConfigProperties.getProperty(key));
                }else if("2".equals(arr[1].toString())){
                    linkedHashMap.put("2Pricing", applicationConfigProperties.getProperty(key));
                }else if("3".equals(arr[1].toString())){
                    linkedHashMap.put("3Reporting", applicationConfigProperties.getProperty(key));
                }else if("4".equals(arr[1].toString())){
                    linkedHashMap.put("4Added Points", applicationConfigProperties.getProperty(key));
                }else if("5".equals(arr[1].toString())){
                    linkedHashMap.put("5Additional Conditions", applicationConfigProperties.getProperty(key));
                }break;
       case 2:
	           if("1".equals(arr[1].toString())){
	               linkedHashMap.put("1Eligiblity to invest", applicationConfigProperties.getProperty(key));
	           }else if("2".equals(arr[1].toString())){
	               linkedHashMap.put("2Pricing", applicationConfigProperties.getProperty(key));
	           }else if("3".equals(arr[1].toString())){
	               linkedHashMap.put("3Reporting", applicationConfigProperties.getProperty(key));
	           }else if("4".equals(arr[1].toString())){
	               linkedHashMap.put("4Final Decision", applicationConfigProperties.getProperty(key));
	           }else if("5".equals(arr[1].toString())){
	               linkedHashMap.put("5Additional Conditions", applicationConfigProperties.getProperty(key));
	           }break;
       case 3:
            	if("1".equals(arr[1].toString())){
                    linkedHashMap.put("1Eligibility", applicationConfigProperties.getProperty(key));
                }else if("2".equals(arr[1].toString())){
                    linkedHashMap.put("2Purchase Consideration", applicationConfigProperties.getProperty(key));
                }else if("3".equals(arr[1].toString())){
                    linkedHashMap.put("3Repatriation of Sale Proceeds", applicationConfigProperties.getProperty(key));
                }else if("4".equals(arr[1].toString())){
                    linkedHashMap.put("4Reporting", applicationConfigProperties.getProperty(key));
                }else if("5".equals(arr[1].toString())){
                    linkedHashMap.put("5Notes", applicationConfigProperties.getProperty(key));
                }else if("6".equals(arr[1].toString())){
 	               linkedHashMap.put("6Additional Conditions", applicationConfigProperties.getProperty(key));
 	           }break;
       case 4:
            	if("1".equals(arr[1].toString())){
                    linkedHashMap.put("1Eligibility", applicationConfigProperties.getProperty(key));
                }else if("2".equals(arr[1].toString())){
                    linkedHashMap.put("2Limits of drawals", applicationConfigProperties.getProperty(key));
                }else if("3".equals(arr[1].toString())){
                    linkedHashMap.put("3Other Important points", applicationConfigProperties.getProperty(key));
                }else if("4".equals(arr[1].toString())){
                    linkedHashMap.put("4Notes", applicationConfigProperties.getProperty(key));
                }break;
       case 5:
            	if("1".equals(arr[1].toString())){
                    linkedHashMap.put("1Eligibility", applicationConfigProperties.getProperty(key));
                }else if("2".equals(arr[1].toString())){
                    linkedHashMap.put("2Note", applicationConfigProperties.getProperty(key));
                }else if("3".equals(arr[1].toString())){
                    linkedHashMap.put("3Others", applicationConfigProperties.getProperty(key));
                }break;
       case 6:
            	if("1".equals(arr[1].toString())){
                    linkedHashMap.put("1Eligibility", applicationConfigProperties.getProperty(key));
                }else if("2".equals(arr[1].toString())){
                    linkedHashMap.put("2Mode of payment", applicationConfigProperties.getProperty(key));
                }else if("3".equals(arr[1].toString())){
                    linkedHashMap.put("3Limit of Investment", applicationConfigProperties.getProperty(key));
                }else if("4".equals(arr[1].toString())){
                    linkedHashMap.put("4Type of facilities", applicationConfigProperties.getProperty(key));
                }else if("5".equals(arr[1].toString())){
                    linkedHashMap.put("5Valuation of shares", applicationConfigProperties.getProperty(key));
                }else if("6".equals(arr[1].toString())){
                    linkedHashMap.put("6Transaction Reporting", applicationConfigProperties.getProperty(key));
                }else if("7".equals(arr[1].toString())){
                    linkedHashMap.put("7Annual Reporting", applicationConfigProperties.getProperty(key));
                }else if("8".equals(arr[1].toString())){
                    linkedHashMap.put("8Additional obligations of Indian Party", applicationConfigProperties.getProperty(key));
                }else if("9".equals(arr[1].toString())){
                    linkedHashMap.put("9Notes", applicationConfigProperties.getProperty(key));
                }break;
      case 7:		
            	if("1".equals(arr[1].toString())){
                    linkedHashMap.put("1Eligibility", applicationConfigProperties.getProperty(key));
                }else if("2".equals(arr[1].toString())){
                    linkedHashMap.put("2Activities that can be undertaken", applicationConfigProperties.getProperty(key));
                }else if("3".equals(arr[1].toString())){
                    linkedHashMap.put("3Procedure", applicationConfigProperties.getProperty(key));
                }else if("4".equals(arr[1].toString())){
                    linkedHashMap.put("4Intimation", applicationConfigProperties.getProperty(key));
                }else if("5".equals(arr[1].toString())){
                    linkedHashMap.put("5Annual Reporting", applicationConfigProperties.getProperty(key));
                }else if("6".equals(arr[1].toString())){
                    linkedHashMap.put("6Additional Responsibilities", applicationConfigProperties.getProperty(key));
                }else if("7".equals(arr[1].toString())){
                    linkedHashMap.put("7Note", applicationConfigProperties.getProperty(key));
                }break;
      case 8:	
		    	if("0".equals(arr[1].toString())){
		              linkedHashMap.put("0Eligibility", applicationConfigProperties.getProperty(key));
		        }else if("1".equals(arr[1].toString())){
                    linkedHashMap.put("1Mode of payment", applicationConfigProperties.getProperty(key));
                }else if("2".equals(arr[1].toString())){
                    linkedHashMap.put("2Form of Loan", applicationConfigProperties.getProperty(key));
                }else if("3".equals(arr[1].toString())){
                    linkedHashMap.put("3Rate of interest", applicationConfigProperties.getProperty(key));
                }else if("4".equals(arr[1].toString())){
                    linkedHashMap.put("4Period of loan", applicationConfigProperties.getProperty(key));
                }else if("5".equals(arr[1].toString())){
                    linkedHashMap.put("5Credit the interest/ repayment of loan", applicationConfigProperties.getProperty(key));
                }else if("6".equals(arr[1].toString())){
                    linkedHashMap.put("6Reporting", applicationConfigProperties.getProperty(key));
                }else if("7".equals(arr[1].toString())){
                    linkedHashMap.put("7Usage of borrowed Funds", applicationConfigProperties.getProperty(key));
                }else if("8".equals(arr[1].toString())){
                    linkedHashMap.put("8Additional Points", applicationConfigProperties.getProperty(key));
                }break;
      case 9:	
		      	if("1".equals(arr[1].toString())){
		            linkedHashMap.put("1Eiligibility", applicationConfigProperties.getProperty(key));
		        }else if("2".equals(arr[1].toString())){
		            linkedHashMap.put("2Mode of Payment", applicationConfigProperties.getProperty(key));
		        }else if("3".equals(arr[1].toString())){
		            linkedHashMap.put("3Acquisition from/to", applicationConfigProperties.getProperty(key));
		        }else if("4".equals(arr[1].toString())){
		            linkedHashMap.put("4Conditions", applicationConfigProperties.getProperty(key));
		        }else if("5".equals(arr[1].toString())){
		            linkedHashMap.put("5Others", applicationConfigProperties.getProperty(key));
		        }break;
            }
           }
        }
	    }
	    TreeMap tm=new TreeMap(linkedHashMap);
        request.setAttribute("LINKEDHASHMAP", tm);
	    }//Ends.
        selectedValue ="";
	    return mapping.findForward("success");

	  } // End execute()

}// End class
